#include "view_time_5.h"
#include "view_time_5.inc"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font_mngr.h"
//#include "view_common.h"
#include "app_trace.h"

void view_time_5_display(void)
{
    bool is_ble_connected = false;
    int hour = 0;
    int minute = 0;
    int day = 0;
    int week_index = 0;
    bool is_charge = false;
    int battery_percent = 0;
    int show_index = 0;
    //    int battery_level = 0;
    is_ble_connected = disp_ctrl.com_data.u_temp[1];
    hour = disp_ctrl.com_data.u_temp[6];
    minute = disp_ctrl.com_data.u_temp[7];
    day = disp_ctrl.com_data.u_temp[5];
    week_index = disp_ctrl.com_data.u_temp[9] - 1;
    is_charge = disp_ctrl.com_data.u_temp[2];
    battery_percent = disp_ctrl.com_data.u_temp[3];
    show_index = disp_ctrl.auto_refresh_count;
    // battery_level = battery_ctrl_get_level(battery_percent);

    draw_on_chip_image(0, 0, time_5_back);
    if (is_ble_connected)
    {
        draw_on_chip_image_ext(1, 2, time_5_ble, draw_type_filter_color);
    }
    else
    {
    }

    int battery_back_width = 17;
    int battery_back_height = 8;
    int battery_back_x = 60;
    int battery_back_y = 2;
    draw_rectangle_empty(battery_back_x, battery_back_y, battery_back_x + battery_back_width - 1, battery_back_y + battery_back_height - 1, RGB565_COLOR_WHITE);
    draw_vertical_line(78, 3, 3 + 6 - 1, RGB565_COLOR_WHITE);
    if (is_charge && show_index % 2 == 0)
    {
        // no thing
    }
    else
    {
        int battery_width = 13;
        int battery_height = 4;
        int battery_x = 62;
        int battery_y = 4;
        int height = battery_width * battery_percent / 100;
        draw_rectangle(battery_x, battery_y, battery_x + height - 1, battery_y + battery_height - 1, RGB565_COLOR_WHITE);
    }

    const unsigned char *week_img = time_5_week_TAB[week_index];
    draw_on_chip_image_ext(4, 132, week_img, draw_type_filter_color);
    draw_on_chip_image_num_with_digits(day, 2, 41, 132, num_8x10_TAB, 8, 1, draw_type_filter_color);
    draw_on_chip_image_num_with_digits(hour, 2, 4, 17, num_29x50_blue_TAB, 29, 6, draw_type_filter_color);
    draw_on_chip_image_num_with_digits(minute, 2, 4, 74, num_29x50_white_TAB, 29, 6, draw_type_filter_color);
}
